package net.inxweb.bluemeerkat.domain.model.glossary;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.ws.rs.FormParam;
import javax.ws.rs.PathParam;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "glossaryType")
@Entity
@Table(name = "TBL_GLS_TYPE")
public class GlossaryType implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "GLS_TYPE_ID")
	private Long id;

	@Column(name = "GLS_TYPE_NM", length = 50)
	@FormParam("name")
	private String name;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@MapKey(name = "id")
	private Map<Long, Attribute> attributes;

	public GlossaryType() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public GlossaryType(String name) {
		super();
		this.name = name;
	}

	public Attribute getAttribute(Long id) {
		return attributes.get(id);
	}

	public Map<Long, Attribute> getAttributes() {
		return attributes;
	}

	public void setAttributes(Map<Long, Attribute> attributes) {
		this.attributes = attributes;
	}

	public void addAttribute(Attribute attribute) {
		if (this.attributes == null) {
			this.attributes = new HashMap<Long, Attribute>();
		}

		this.attributes.put(attribute.getId(), attribute);
	}

	@Override
	public String toString() {
		return "GlossaryType [attributes=" + attributes + ", id=" + id
				+ ", name=" + name + "]";
	}
}
